#include <stdio.h>
#include <conio.h>
#include <math.h>


  float matrix[4][4],B[4],X[500][4] = {0},TEST[4],summ,eps;
  int    i,k,a,b;


void printarr(float matrix[4][4],float B[4]);

    main()
	{	
    FILE *inf,*outf;
    outf= stdout;
    
    fprintf(outf, "gauss\n");                                  
    fprintf(outf, "2102\n");
    fprintf(outf, "Mikhailov Vlad\n");
    fprintf(outf, "\n");
    fprintf(outf, "Enter a:");
    scanf("%d",&a);
    getchar();
    fprintf(outf, "Enter b:");
    scanf("%d",&b);
    getchar();
    fprintf(outf, "Enter eps:");
    scanf("%f",&eps);
    getchar();
    
    matrix[0][0] = a-6;
    matrix[0][1] = 1;
    matrix[0][2] = 1;
    matrix[0][3] = 1;
    matrix[1][0] = 1;
    matrix[1][1] = a-4;
    matrix[1][2] = 1;
    matrix[1][3] = 1;
    matrix[2][0] = 1;
    matrix[2][1] = 1;
    matrix[2][2] = a-2;
    matrix[2][3] = 1;
    matrix[3][0] = 1;
    matrix[3][1] = 1;
    matrix[3][2] = 1;
    matrix[3][3] = a;
    B[0]=b-4;
    B[1]=b-2;
    B[2]=b;
    B[3]=b+2; 
    
    printarr(matrix,B);

	do 
{
for(int i=0; i<4; i++)        
   {
   summ = 0;
   for(int j=0; j<4; j++)
      if(i!=j)
         summ += matrix[i][j] * X[k][j];			   		    
      X[k+1][i] = (1/matrix[i][i]) * (B[i] - summ);			
    }
k++;    
}while(fabs(X[k][i]-X[k-1][i]) > eps);


printf("\nResult:\n");
for(int j=0; j<4; j++)
   printf("%4.8f   ",X[k][j]); 

printf("\nTest:\n");
for(int i=0; i<4; i++)
   {
   for(int j=0; j<4; j++)
      TEST[i] +=(matrix[i][j] * X[k][j]);
   printf("%2.9f  ", TEST[i]);
   }

getchar();
}
void printarr(float matrix[4][4],float B[4])
{
  int i,j;
     for(i=0;i<=3;i++,printf("\n"))
  {                 
     for(j=0;j<4;j++)
     printf( "%2.9f""  ", matrix[i][j]);
     printf( "%2.9f""  ", B[i]);
  }
return;    
}
